home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / ms-0.07 / xms / xio.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-27  |  2.0 KB  |  70 lines

  1. /* xio.c -- glue between Xt and the I/O module */
  2.  
  3. /*
  4.     This file is part of MandelSpawn, a network Mandelbrot program.
  5.  
  6.     Copyright (C) 1990-1993 Andreas Gustafsson
  7.  
  8.     MandelSpawn is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License, version 1,
  10.     as published by the Free Software Foundation.
  11.  
  12.     MandelSpawn is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License,
  18.     version 1, along with this program; if not, write to the Free 
  19.     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. #include <X11/Intrinsic.h>
  23. #include "io.h"
  24.  
  25. extern XtAppContext thisApp;
  26.  
  27. /* Ugly state variables */
  28.  
  29. static XtInputId xio_input_id;
  30. static int xio_recv_fd;
  31.  
  32.  
  33. /* Callback function to be called when data arrives from a slave */
  34.  
  35. static void 
  36. MsSocketInputCallback(client_data, source, id)
  37.      caddr_t client_data; int *source; XtInputId *id;
  38. { io_state *io = (io_state *) client_data;
  39.   if(*id != xio_input_id || *source != xio_recv_fd)
  40.   { XtAppError(thisApp, "unexpected input from computation server");
  41.   }
  42.   io_handle_socket_input(io);
  43. }
  44.  
  45.  
  46. static void 
  47. TimeoutCallback(client_data, id) 
  48.      caddr_t client_data;
  49.      XtIntervalId *id;
  50. { io_state *io = (io_state *) client_data;
  51.   io_tick(io);
  52.   /* reset the timeout */
  53.   XtAppAddTimeOut(thisApp, 1000,
  54.           (XtTimerCallbackProc) TimeoutCallback, client_data);
  55. }
  56.  
  57. void xio_init(io)
  58.   io_state *io;
  59. { xio_recv_fd = io_get_recv_fd(io);
  60.   /* pass a pointer to the I/O state struct as "client data" */
  61.   xio_input_id = 
  62.     XtAppAddInput(thisApp,
  63.           xio_recv_fd,
  64.           (caddr_t) XtInputReadMask,
  65.           (XtInputCallbackProc) MsSocketInputCallback,
  66.           (caddr_t) io);
  67.   (void) XtAppAddTimeOut(thisApp, 1000,
  68.           (XtTimerCallbackProc) TimeoutCallback, (caddr_t) io);
  69. }
  70.